package com.test.nio;

import com.sun.istack.internal.NotNull;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;
import java.nio.channels.FileChannel;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.Arrays;
import java.util.EnumSet;

public class BufferMain {
    public static void main(String[] args) throws Exception {
        FileChannel in = FileChannel.open(Paths.get("D://test.log"), StandardOpenOption.READ);
        FileChannel out = FileChannel.open(Paths.get("D://test.txt"), StandardOpenOption.CREATE, StandardOpenOption.WRITE);
        ByteBuffer buffer = ByteBuffer.allocate(1024);
        while (in.read(buffer) != -1) {
            buffer.flip();//从写模式切换到读模式
            out.write(buffer);
            buffer.clear();//让Buffer准备再次写入
        }
        out.close();
        in.close();
    }
}
